/**
 * 
 */
package net.phoenix.repository.nodetype;

import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;

/**
 * @author lixf
 * 
 */
public abstract class GeneralNodeDefinition extends XMLItemDefinition implements NodeDefinition {
	protected GeneralNodeTypeManager manager;
	protected GeneralNodeType parent;

	public GeneralNodeDefinition(GeneralNodeTypeManager manager, GeneralNodeType nodeType) {
		this.manager = manager;
		this.parent = nodeType;
	}

	@Override
	public NodeType[] getRequiredPrimaryTypes() {
		return new NodeType[] { this.getDefaultPrimaryType() };
	}

	@Override
	public String[] getRequiredPrimaryTypeNames() {
		return new String[] { this.getDefaultPrimaryTypeName() };
	}

	@Override
	public NodeType getDefaultPrimaryType() {
		try {
			return this.manager.getNodeType(getDefaultPrimaryTypeName());
		} catch (NoSuchNodeTypeException e) {
			return null;
		}
	}

	@Override
	public NodeType getDeclaringNodeType() {
		return this.parent;
	}

	@Override
	public int getOnParentVersion() {
			return 0;
	}

}
